package com.laxcen.controller2;

import com.laxcen.smoke.config.MyLog;
import com.laxcen.smoke.dto.req.AdvertisementInsertReq;
import com.laxcen.smoke.dto.req.AdvertisementTabByConditionReq;
import com.laxcen.smoke.dto.req.AdvertisementUpdateReq;
import com.laxcen.smoke.dto.req.CommonOneIdReq;
import com.laxcen.smoke.dto.res.AdvertisementAndNoRes;
import com.laxcen.smoke.entity.Smart;
import com.laxcen.smoke.service.AdvertisementService;
import com.laxcen.smoke.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

@Api(tags = "广告管理")
@RestController
@RequestMapping("/adver")
public class AdvertisementController {

    @Autowired
    private AdvertisementService advertisementService;

    @ApiOperation(value = "添加广告图",notes =
            "请求信息： \n" +
                    "&emsp; adverimg &nbsp; : &nbsp; 广告图base64字节流(多个文件流中间用,隔开) \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/insert")
   @RequiresPermissions("adver:insert")
    @MyLog(operation = "添加广告图")
    public Response<Smart> insert(@RequestBody AdvertisementInsertReq advertisementInsertReq){
        return advertisementService.insert(advertisementInsertReq.getAdverimg());
    }

    @ApiOperation(value = "删除广告图",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 广告图id \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/delete")
    @MyLog(operation = "删除广告图")
    @RequiresPermissions("adver:delete")
    public Response delete(@RequestBody CommonOneIdReq commonOneIdReq){
        return advertisementService.delete(commonOneIdReq.getId());
    }


    @ApiOperation(value = "修改广告图",notes =
            "请求信息： \n" +
                    "&emsp; adverimg &nbsp; : &nbsp; 广告图base64字节流(多个文件流中间用,隔开) \n" +
                    "&emsp; id &nbsp; : &nbsp; 广告id \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/update")
    @MyLog(operation = "修改广告图")
//    @RequiresPermissions("adver:update")
    public Response<Smart> update(@RequestBody AdvertisementUpdateReq advertisementUpdateReq){
        return advertisementService.update(advertisementUpdateReq.getAdverimg(),advertisementUpdateReq.getId());
    }

    @ApiOperation(value = "获取广告图列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 广告id \n" +
                    "&emsp; adverimg &nbsp; : &nbsp; 广告图片路径 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp; updatetime &nbsp; : &nbsp; 修改时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @RequiresPermissions("adver")
    @PostMapping(value = "/getlist")
    public Response<List<AdvertisementAndNoRes>> getList(){
        return advertisementService.getList();
    }

    @ApiOperation(value = "获取某一个广告图详情",notes =
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 广告id \n" +
                    "&emsp; adverimg &nbsp; : &nbsp; 广告图片路径 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp; updatetime &nbsp; : &nbsp; 修改时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getone")
    @RequiresPermissions("adver:getone")
    public Response<AdvertisementAndNoRes> getOne(@RequestBody CommonOneIdReq commonOneIdReq){
        return advertisementService.getOneAdv(commonOneIdReq.getId());
    }


    @ApiOperation(value = "导航栏搜索广告图列表",notes =
            "请求信息： \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; starttime &nbsp; : &nbsp; 时间左区间 \n" +
                    "&emsp; endtime &nbsp; : &nbsp; 时间右区间 \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 广告id \n" +
                    "&emsp; adverimg &nbsp; : &nbsp; 广告图片路径 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp; updatetime &nbsp; : &nbsp; 修改时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/gettabforlist")
    @RequiresPermissions("adver:gettabforlist")
    public Response<List<AdvertisementAndNoRes>> getTabForList(@RequestBody AdvertisementTabByConditionReq advertisementTabByConditionReq) throws ParseException {
        return advertisementService.getListByCondition(advertisementTabByConditionReq.getStarttime(),advertisementTabByConditionReq.getEndtime());
    }


}
